package team.mutong.taxi.domain;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.naming.spi.DirStateFactory.Result;

import libsvm.svm_node;
import team.mutong.taxi.ecc.EccAlgorithm;
import team.mutong.taxi.jdbc.DataBase;
import team.mutong.taxi.utils.GetFeature;

public class clusterFeater {
	public static List<List>  clusterfeater(List<Map<String,Object>> testSet) {
		int feature = 31;
		//List<DtwFeature> train = DataBase.getTestTrace();
		List<svm_node[]> Result = new ArrayList<>(); 
		List<String> resultTripId = new ArrayList<>();
		List<List> reResult = new ArrayList<>();
		
		for(int k = 0;k<testSet.size();k++){
			//System.out.println(k);
			List<svm_node[]> featerSet = new ArrayList<svm_node[]>();
			svm_node[] featerTest = new svm_node[feature];
			List<List<GPSPoint>> sourseTrace = new ArrayList<>();
			List<DtwFeature> result = DataBase.getDTWresult( (String) testSet.get(k).get("TRIP_ID"));
			if (result.size() == 0) {
				System.out.println("AA:这条数据为空,跳过");
				continue;
			}
			List<DtwFeature> train = DataBase.getTestFeatureByTripId("tomwang_test",(String) testSet.get(k).get("TRIP_ID")); 
			System.out.println(train.size());
			if (train.size() == 0) {
				System.out.println("BB:这条数据为空,跳过");
				continue;
			}
			for(int i=0;i<result.size();i++){		
				svm_node[] vector = new svm_node[23];
				int j = 1;
				svm_node node1 = new svm_node();
				node1.index = j;
				node1.value = GetFeature.getCallTpye(result.get(i));
				vector[j-1] = node1;
				j = j+1;
				svm_node node2 = new svm_node();
				node2.index = j;          
				node2.value = GetFeature.getTaxiId(result.get(i));       
				vector[j-1] = node2; 
				j = j+1;
				svm_node node3 = new svm_node(); 
				node3.index = j;
				node3.value = GetFeature.getTimeStamp(result.get(i));
				vector[j-1] = node3;
				j = j+1;
				svm_node node4 = new svm_node();
				node4.index = j;
				node4.value =GetFeature.getDayTpye(result.get(i));
				vector[j-1] = node4;
				j = j+1;
				svm_node node5 = new svm_node();  
				node5.index = j;
				node5.value = GetFeature.getOriginCall(result.get(i));
				vector[j-1] = node5;
				j = j+1;
				svm_node node6 = new svm_node();
				node6.index = j;
				node6.value =GetFeature.getOriginStand(result.get(i));
				vector[j-1] = node6;
				j = j+1;
				svm_node node7 = new svm_node();  
				node7.index = j;
				node7.value = GetFeature.getTimeA(result.get(i));
				vector[j-1] = node7;
				j = j+1;
				svm_node node8 = new svm_node();
				node8.index = j;
				node8.value =GetFeature.getTimeB(result.get(i));
				vector[j-1] = node8;
				j = j+1;
				svm_node node9 = new svm_node(); 
				node9.index = j;
				node9.value = GetFeature.getTimeC(result.get(i));
				vector[j-1] = node9;
				j = j+1;
				svm_node node10 = new svm_node();
				node10.index = j;
				node10.value =GetFeature.getSpeedA(result.get(i));
				vector[j-1] = node10;
				j = j+1;
				svm_node node11 = new svm_node();  
				node11.index = j;
				node11.value = GetFeature.getSpeedB(result.get(i));
				vector[j-1] = node11;
				j = j+1;
				svm_node node12 = new svm_node();
				node12.index = j;
				node12.value =GetFeature.getSpeedC(result.get(i));
				vector[j-1] = node12;
				j = j+1;
				svm_node node13 = new svm_node();  
				node13.index = j;        
				node13.value = GetFeature.getDistenceA(result.get(i));
				vector[j-1] = node13;
				j = j+1;
				svm_node node14 = new svm_node();
				node14.index = j;
				node14.value =GetFeature.getDistenceB(result.get(i));
				vector[j-1] = node14;
				j = j+1;
				svm_node node15 = new svm_node();  
				node15.index = j;
				node15.value = GetFeature.getDistenceC(result.get(i));
				vector[j-1] = node15;
				j = j+1;
				svm_node node16 = new svm_node();
				node16.index = j;
				node16.value =GetFeature.getCutEndPoint(result.get(i)).getX();
				vector[j-1] = node16;
				j = j+1;
				svm_node node17 = new svm_node();
				node17.index = j;
				node17.value =GetFeature.getCutEndPoint(result.get(i)).getY();
				vector[j-1] = node17;
				j = j+1;
				svm_node node18 = new svm_node();  
				node18.index = j;
				node18.value = GetFeature.getCutStartPoint(result.get(i)).getX();
				vector[j-1] = node18;
				j = j+1;
				svm_node node19 = new svm_node();
				node19.index = j;
				node19.value =GetFeature.getCutStartPoint(result.get(i)).getY();
				vector[j-1] = node19;
				j = j+1;
				svm_node node20 = new svm_node();   
				node20.index = j;
				node20.value =GetFeature.getStartPoint(result.get(i)).getX();
				vector[j-1] = node20;
				j = j+1;
				svm_node node21 = new svm_node();
				node21.index = j;
				node21.value =GetFeature.getStartPoint(result.get(i)).getY();
				vector[j-1] = node21;
				j = j+1;
				svm_node node22 = new svm_node();  
				node22.index = j;
				node22.value = GetFeature.getEndPoint(result.get(i)).getX();
				vector[j-1] = node22;
				j = j+1;
				svm_node node23 = new svm_node();  
				node23.index = j;
				node23.value = GetFeature.getEndPoint(result.get(i)).getY();
				vector[j-1] = node23;
				featerSet.add(vector);	
				sourseTrace.add(i, result.get(i).getCutRoad());
			}
				
			svm_node[] vector = new svm_node[feature];
			int j = 1;
			svm_node node1 = new svm_node();
			node1.index = j;
			node1.value = GetFeature.getCallTpye(train.get(0));
			featerTest[j-1] = node1;
			j = j+1;
			svm_node node2 = new svm_node();
			node2.index = j;          
			node2.value = GetFeature.getTaxiId(train.get(0));       
			featerTest[j-1] = node2; 
			j = j+1;
			svm_node node3 = new svm_node(); 
			node3.index = j;
			node3.value = GetFeature.getTimeStamp(train.get(0));
			featerTest[j-1] = node3;
			j = j+1;
			svm_node node4 = new svm_node();
			node4.index = j;
			node4.value =GetFeature.getDayTpye(train.get(0));
			featerTest[j-1] = node4;
			j = j+1;
			svm_node node5 = new svm_node();  
			node5.index = j;
			node5.value = GetFeature.getOriginCall(train.get(0));
			featerTest[j-1] = node5;
			j = j+1;
			svm_node node6 = new svm_node();
			node6.index = j;
			node6.value =GetFeature.getOriginStand(train.get(0));
			featerTest[j-1] = node6;
			j = j+1;
			svm_node node7 = new svm_node();  
			node7.index = j;
			node7.value = GetFeature.getAllroadTime(train.get(0));
			featerTest[j-1] = node7;
			j = j+1;
			svm_node node8 = new svm_node();
			node8.index = j;
			node8.value = 0;
			featerTest[j-1] = node8;
			j = j+1;
			svm_node node9 = new svm_node(); 
			node9.index = j;
			node9.value = GetFeature.getAllroadTime(train.get(0));
			featerTest[j-1] = node9;
			j = j+1;
			svm_node node10 = new svm_node();
			node10.index = j;
			node10.value =GetFeature.getAllroadAverage(train.get(0));
			featerTest[j-1] = node10;
			j = j+1;
			svm_node node11 = new svm_node();  
			node11.index = j;
			node11.value = 0;
			featerTest[j-1] = node11;
			j = j+1;
			svm_node node12 = new svm_node();
			node12.index = j;
			node12.value =GetFeature.getAllroadAverage(train.get(0));
			featerTest[j-1] = node12;
			j = j+1;
			svm_node node13 = new svm_node();  
			node13.index = j;        
			node13.value = GetFeature.getAllroadDistencd(train.get(0));
			featerTest[j-1] = node13;
			j = j+1;
			svm_node node14 = new svm_node();
			node14.index = j;
			node14.value = 0;
			featerTest[j-1] = node14;
			j = j+1;
			svm_node node15 = new svm_node();  
			node15.index = j;
			node15.value = GetFeature.getAllroadDistencd(train.get(0));
			featerTest[j-1] = node15;
			j = j+1;
			svm_node node16 = new svm_node();
			node16.index = j;
			node16.value =GetFeature.getCutEndPoint(train.get(0)).getX();
			featerTest[j-1] = node16;
			j = j+1;
			svm_node node17 = new svm_node();
			node17.index = j;
			node17.value =GetFeature.getCutEndPoint(train.get(0)).getY();
			featerTest[j-1] = node17;
			j = j+1;
			svm_node node18 = new svm_node();  
			node18.index = j;
			node18.value = GetFeature.getCutStartPoint(train.get(0)).getX();
			featerTest[j-1] = node18;
			j = j+1;
			svm_node node19 = new svm_node();
			node19.index = j;
			node19.value =GetFeature.getCutStartPoint(train.get(0)).getY();
			featerTest[j-1] = node19;
			j = j+1;
			svm_node node20 = new svm_node();   
			node20.index = j;
			node20.value =GetFeature.getCutStartPoint(train.get(0)).getX();
			featerTest[j-1] = node20;
			j = j+1;
			svm_node node21 = new svm_node();
			node21.index = j;
			node21.value =GetFeature.getCutStartPoint(train.get(0)).getY();
			featerTest[j-1] = node21;
			j = j+1;
			svm_node node22 = new svm_node();  
			node22.index = j;
			node22.value = GetFeature.getEndPoint(train.get(0)).getX();
			featerTest[j-1] = node22;
			j = j+1;
			svm_node node23 = new svm_node();  
			node23.index = j;
			node23.value = GetFeature.getEndPoint(train.get(0)).getY();
			featerTest[j-1] = node23;
					
			svm_node[] allNode = EccAlgorithm.getPoints(sourseTrace,GetFeature.getEndPoint(train.get(0)),featerSet,4,featerTest);
			Result.add(allNode);
			resultTripId.add((String) testSet.get(k).get("TRIP_ID"));
		}
//		System.out.println(Result);
		reResult.add(resultTripId);
		reResult.add(Result);
		return reResult;
	}

}
